package com.v5ba.annotation.web;

import com.v5ba.event.EditUser;
import com.v5ba.event.EditUserEvent;
import com.v5ba.event2.AddUser;
import com.v5ba.event2.AddUserEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @Autowired
    private ApplicationContext applicationContext;
    @GetMapping("edit")
    public String get(){
        EditUser editUser = new EditUser();
        editUser.setName("张三");
        EditUserEvent event = new EditUserEvent(editUser);
        applicationContext.publishEvent(event);
        applicationContext.publishEvent(event);
        System.out.println("编辑了用户");
        return "ok";
    }
    @GetMapping("add")
    public String add(){
        AddUser user = new AddUser();
        user.setName("李四");
        AddUserEvent event = new AddUserEvent(user);
        applicationContext.publishEvent(event);
        return "ok";
    }
}

